// indexviews/doctorView/doctorView.js
var servicePath = require("../../utils/servicePath.js"); 
//var util = require('../utils/util.js');
var alert = require('../../utils/alert.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    doctor: null,
    judges: [],
    appDomain: app.globalData.appDomain,
    doctorId:null,
    unuseTime:null,
    orderTime:null,
    userName:"",
    userPhone:"",
    isOpen:true //是否显示详情
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var doctorId = options.id;
    this.setData({
      doctorId: doctorId
    })
    if (doctorId != null) {
      var _this = this;
      wx.request({
        url: servicePath.SingleDoctorService() + "?doctorId=" + doctorId,
        method: "GET",
        success: function (res) {
          //医生信息
          var result = [];
          console.log(res.data.condition.aP0104)
          if (res.data.condition.aP0104 != null && res.data.condition.aP0104 != "") {
            var tmp = res.data.condition.aP0104.split("、");
            for (var i = 0; i < tmp.length; i++) {
              result.push({ name: tmp[i], value: tmp[i]})
            }
          }

          console.log(res.data.condition);
          _this.setData({
            doctor: res.data.condition,
            unuseTime: result
          });
        }
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  radioChange: function (e) {
    var unuseTime = this.data.unuseTime;
    console.log(e.detail);
    for (var i = 0, len = unuseTime.length; i < len; ++i) {
      unuseTime[i].checked = unuseTime[i].value == e.detail.value;
    }

    this.setData({
      unuseTime: unuseTime,
      orderTime:e.detail.value
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  userInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },
  phoneInput: function (e) {
    this.setData({
      userPhone: e.detail.value
    })
  },
  //预约挂号
  orderDoctor:function(){
  
    if(this.data.orderTime == null){
      alert.toast("请选择预约时间");
      return;
    }
    var url = app.globalData.apiDoamin + "/Appointment";
 
    var _this = this;
    let backUser = app.globalData.backUserInfo;
    wx.request({
      url: url,
      method:"POST",
      data:{
        AP0302: _this.data.doctor.aP0100,
        AP0303: _this.data.doctor.aP0101,
        AP0300: backUser.syS0100,
        AP0304: _this.data.orderTime
      },
      success:function(res){
        if (res.data.code == 200) {
          wx.showModal({
            content: '预约成功，办理成功后会以短信形式通知您！',
            showCancel: false,
            success: function (res) {
              wx.navigateBack({

              });
            }
          });
        }
      }
    })
  },
  closeView:function(){
    this.setData({
      isOpen:!this.data.isOpen
    })
  }
})